<%= header %>
<%= boomerangScript %>

<script src="28-wait-for-all-nodes.js" type="text/javascript"></script>
<script type="text/javascript">
var beaconCount = 0;
BOOMR.subscribe("beacon", function(vars) {
	var xhr, img2;
	beaconCount++;
	if (beaconCount === 1) {
		setTimeout(function() {
			xhr = new XMLHttpRequest();
			xhr.open("GET", "/delay?delay=400&id=xhr&file=/pages/07-autoxhr/support/script200.js&rnd=" + Math.random());
			xhr.addEventListener("load", function() {
				// this img will start after the xhr has completed and will be tracked
				img2 = document.createElement("img");
				img2.src = "/delay?delay=1000&id=img2&file=/pages/07-autoxhr/support/img.jpg&rnd=" + Math.random();
				document.body.appendChild(img2);
				setTimeout(function() {
					// this img will start while the xhr is in progress and should not be tracked
					var img3;
					img3 = document.createElement("img");
					img3.src = "/delay?delay=1000&id=img3&file=/pages/07-autoxhr/support/img.jpg&rnd=" + Math.random();
					document.body.appendChild(img3);
				}, 200);
			});
			xhr.send(null);
			setTimeout(function() {
				// this img will start while the xhr is in progress and should not be tracked
				var img1;
				img1 = document.createElement("img");
				img1.src = "/delay?delay=2000&id=img1&file=/pages/07-autoxhr/support/img.jpg&rnd=" + Math.random();
				document.body.appendChild(img1);
			}, 50);
		}, 100);
	}
});
BOOMR_test.init({
	testAfterOnBeacon: BOOMR.plugins.AutoXHR ? 2 : 1,
	instrument_xhr: true
});
</script>
